package mate_preference

import (
	"context"

	commonTools "algo-sdk-go/common/tools"
	"algo-sdk-go/project/matchmaking/common/constant"
	"algo-sdk-go/project/matchmaking/domain/models/entity"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/svc"
	"algo-sdk-go/project/matchmaking/matchMaking-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type QueryMatePreferenceLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewQueryMatePreferenceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QueryMatePreferenceLogic {
	return &QueryMatePreferenceLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *QueryMatePreferenceLogic) QueryMatePreference(req *types.QueryMatePreferenceRequest) (resp *types.QueryMatePreferenceResponse, err error) {
	preferenceList, err := l.svcCtx.MatePreferenceService.GetMatePreference(l.ctx, req.UserNumList)
	if err != nil {
		return nil, err
	}

	resp = &types.QueryMatePreferenceResponse{
		Data: types.QueryMatePreferenceData{
			MatePreferenceList: commonTools.Cast(preferenceList, preferenceCast),
		},
	}
	return
}

func preferenceCast(userAllInfo entity.MatePreference) types.MatePreference {
	data := types.MatePreference{
		//ID:                       userAllInfo.Hometown,
		UserNum:   userAllInfo.UserNum,
		Standards: userAllInfo.Standards,

		AgeRange: types.AgeRange{
			MinAge: userAllInfo.AgeRange.MinAge,
			MaxAge: userAllInfo.AgeRange.MaxAge,
		},
		HeightRange: types.HeightRange{
			MinHeight: userAllInfo.HeightRange.MinHeight,
			MaxHeight: userAllInfo.HeightRange.MaxHeight,
		},
		WeightRange: types.WeightRange{
			MinWeight: userAllInfo.WeightRange.MinWeight,
			MaxWeight: userAllInfo.WeightRange.MaxWeight,
		},
		IncomeRange: types.IncomeRange{
			MinIncome: userAllInfo.IncomeRange.MinIncome,
			MaxIncome: userAllInfo.IncomeRange.MaxIncome,
		},
		EducationRange: types.EducationRange{
			MinEducation: userAllInfo.EducationRange.MinEducation.Value(),
			MaxEducation: userAllInfo.EducationRange.MaxEducation.Value(),
		},

		OccupationRequire:        commonTools.Cast(userAllInfo.OccupationPreference, constant.Occupation.Value),
		CurrentResidenceRequired: commonTools.Cast(userAllInfo.CurrentResidencePreference, AddressDeCast),
		HometownRequired:         commonTools.Cast(userAllInfo.HometownPreference, AddressDeCast),
		PersonalityTraits:        userAllInfo.PersonalityTraits,
		OtherRequired:            userAllInfo.OtherRequired,
		CreateUser:               "",
		ModifyUser:               "",
	}
	return data
}
